<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <style type="text/css">
        #div_random
        {
            height: 261px;
            width: 341px;
            margin-top:300px;
        }
    </style>
</head>
<script type='text/javascript' src='/Ambition/dwr/interface/bdao.js'></script>
  <script type='text/javascript' src='/Ambition/dwr/engine.js'></script>
  <script type='text/javascript' src='/Ambition/dwr/util.js'></script>
<body style="background-color: green;">
                  
               <center>
                 <form  method="post" name="f1">
                  <div id="div_random" style="font-family: 方正姚体; font-size: 50px; font-weight: 900; font-style: inherit; font-variant: normal; color: #0099FF; text-align: center; padding-top: 150px; background: url('images/20161112105801.png') max-height:261px max-width:341px">
                  00000000000
                  </div>
                  <input type="button" value="开始摇号" onclick="Start()" id="btn_start" style="font-family: 方正姚体; font-size: xx-large; font-weight: 400; font-style: inherit; color: #FF0000; background-color: #FFFFCC"/>
                  <input type="hidden" id="tel" name="tel"/>
                  <input type="button" value="停    止" onclick="Stop()" id="btn_stop" style=" display:none;font-family: 方正姚体; font-size: xx-large; font-weight: 400; font-style: inherit; color: #FF0000; background-color: #FFFFCC"/> 
                  <!--  <input type="" value="确定" onclick="update()"/>-->
                 </form>
               </center>
               <% System.out.println("tuserid:"+session.getAttribute("userId").toString());%>
</body>
</html>    
        <script type="text/javascript">
            var int;
            var randomNum;
            var speed=80;
            var arr=new Array();
            var tel;
           
            
            function callback(result){
               
            	arr=result;
                randomNum=arr.length;
            }
            
            function random() {
                var num = Math.random();
                num = Math.ceil(num * randomNum)-1;
                document.getElementById("div_random").innerHTML =arr[num];
                tel=arr[num];
            }
            function Start() {
                
                usreId=<%=Integer.parseInt(session.getAttribute("userId").toString())%>;
                bdao.selectTel(usreId,callback);
                int = setInterval(random, speed);
                document.getElementById("btn_start").style.display = "none";
                document.getElementById("btn_stop").style.display = "";
            }
            function Stop() {
           
                bdao.updateState(1,tel); 
            	document.getElementById("tel").value=tel;
            	alert("恭喜"+tel+"手机号获得一次抽奖机会");
                clearInterval(int); 
                document.getElementById("btn_start").style.display = "";
                document.getElementById("btn_stop").style.display = "none";
                location.href="javascript:f1.action='ShowOneBbs.bbs?lujing=ShowOneSweepstake.sweep&lujing1=ShowSweepstakeUser.suser';f1.submit()";
            }
            
    </script>
    
